#pragma once

#include "Bounds.h"


namespace uml {

const double Bounds::x_default_ = 0;
const double Bounds::y_default_ = 0;
const double Bounds::width_default_ = 0.0;
const double Bounds::height_default_ = 0.0;
void Bounds::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    x_ = json.value("x").toDouble(x_default_);
    y_ = json.value("y").toDouble(y_default_);
    width_ = json.value("width").toDouble(width_default_);
    height_ = json.value("height").toDouble(height_default_);
}

void Bounds::toJson(QJsonObject& json) {
    if (x_ != x_default_) {
        json.insert("x", x_);
    }
    if (y_ != y_default_) {
        json.insert("y", y_);
    }
    if (width_ != width_default_) {
        json.insert("width", width_);
    }
    if (height_ != height_default_) {
        json.insert("height", height_);
    }
}

/// <summary>
/// x getter
/// a real number (>=0 or <=0) that represents the x-coordinate of the bounds
/// </summary>
double Bounds::x() const {
    return x_;
}

/// <summary>
/// x setter
/// a real number (>=0 or <=0) that represents the x-coordinate of the bounds
/// </summary>
void Bounds::setX(double value) {
    x_ = value;
}

/// <summary>
/// y getter
/// a real number (>=0 or <=0) that represents the y-coordinate of the bounds
/// </summary>
double Bounds::y() const {
    return y_;
}

/// <summary>
/// y setter
/// a real number (>=0 or <=0) that represents the y-coordinate of the bounds
/// </summary>
void Bounds::setY(double value) {
    y_ = value;
}

/// <summary>
/// width getter
/// a real number (>=0) that represents the width of the bounds
/// </summary>
double Bounds::width() const {
    return width_;
}

/// <summary>
/// width setter
/// a real number (>=0) that represents the width of the bounds
/// </summary>
void Bounds::setWidth(double value) {
    width_ = value;
}

/// <summary>
/// height getter
/// a real number (>=0) that represents the height of the bounds
/// </summary>
double Bounds::height() const {
    return height_;
}

/// <summary>
/// height setter
/// a real number (>=0) that represents the height of the bounds
/// </summary>
void Bounds::setHeight(double value) {
    height_ = value;
}

} // namespace uml
